QMenu

您所在的位置:网站首页 qmenu 位置 QMenu

QMenu

2023-10-23 00:51| 来源: 网络整理| 查看: 265

A menu consists of a list of action items. Actions are added with the addAction() , addActions() and insertAction() functions. An action is represented vertically and rendered by QStyle . In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as “Ctrl+X”.

The existing actions held by a menu can be found with actions() .

There are four kinds of action items: separators, actions that show a submenu, widgets, and actions that perform an action. Separators are inserted with addSeparator() , submenus with addMenu() , and all other items are considered action items.

When inserting action items you usually specify a receiver and a slot. The receiver will be notified whenever the item is triggered() . In addition, QMenu provides two signals, triggered() and hovered() , which signal the QAction that was triggered from the menu.

You clear a menu with clear() and remove individual action items with removeAction() .

A QMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to “tear off” frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with setTearOffEnabled() . When using tear-off menus, bear in mind that the concept isn’t typically used on Microsoft Windows so some users may not be familiar with it. Consider using a QToolBar instead.

Widgets can be inserted into menus with the QWidgetAction class. Instances of this class are used to hold widgets, and are inserted into menus with the addAction() overload that takes a QAction . If the QWidgetAction fires the triggered() signal, the menu will close.

Warning

To make QMenu visible on the screen, exec() or popup() should be used instead of show() .



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3